/***************************************************************************
 *   Copyright (C) 2005 by xihe                                            *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef _FRIEND_INFO_H_
#define _FRIEND_INFO_H_
#include "BuddyInfo.h"
#include "QQBuddy.h"
#include <ext/hash_map>
#include <functional>
using __gnu_cxx::hash_map;
using std::unary_function;

class FriendInfo : public BuddyInfo {
    public:
	void setNickname(const string& _nickname) { nickname = _nickname; }

	uint16_t getFace() const { return face; }
	uint8_t  getAge()  const { return age; }
	uint8_t  getSex()  const { return sex; }
	uint8_t  getGroup() const { return group; }
	void	 setGroup(int32_t _group) { group = _group; }

	bool hasQQShow() const { return extend.qqShow == 1; }
	bool isMember()	const { return common.member == 1; }
	bool isTcp()    const { return common.tcp == 1; }
	bool isMobile() const { return common.mobile == 1; }
	bool isPhone()  const { return common.phone == 1; }
	bool isVideo()  const { return common.video == 1; }

	uint32_t getIp()     const { return ip; }
	uint16_t getPort()   const { return port; }
	uint8_t  getStatus() const { return status; }
	void	 setStatus(uint8_t _status) { status = _status; }
	bool	 isOnline() const { return QQ_FRIEND_STATUS_ONLINE == status; }
	bool	 isAway()   const { return QQ_FRIEND_STATUS_AWAY == status; };

	explicit FriendInfo(uint32_t _uid, 
		uint8_t _status = QQ_FRIEND_STATUS_ONLINE);
	explicit FriendInfo(const QQGroupFriend& rhs);
	explicit FriendInfo(const QQBuddy& rhs);
	explicit FriendInfo(const QQBuddyStatus& rhs);
	FriendInfo& operator = (const QQBuddy& rhs) ;
	FriendInfo& operator = (const QQBuddyStatus& rhs);
	FriendInfo& operator = (uint32_t _uid)
	{
	    status = QQ_FRIEND_STATUS_ONLINE; 
	}
	FriendInfo& operator = (const QQGroupFriend& rhs)
	{
	    group = rhs.group / 4;
	    return *this;
	}
	
    private:
	uint32_t    ip;		// ip地址
	uint32_t    group;	// 分组
	uint16_t    port;	// 端口
	uint16_t    face;	// 头像
	uint8_t	    age;	// 年龄
	uint8_t	    sex;	// 性别
	uint8_t	    status;	// 状态
	QQBuddy::Extend extend;
	QQBuddy::Common common;

};

struct SetStatus : public 
		   unary_function<
		   FriendInfo*,
		   void> 
{
    SetStatus(uint8_t _status) : status(_status){}
    void operator ()(FriendInfo* iter)

    {
	    iter->setStatus(status);
    }
    uint8_t status;
};


#endif // _FRIEND_INFO_H_

